package functions;

public class Ln extends Term {
	private Function function;

	public Ln(double coff, double exp, Function poly)
	{
		this.function = poly;
		this.coff = coff;
		this.expon = exp;
	}

	@Override
	public double eval(double x)
	{
		return coff * Math.pow(Math.log(function.eval(x)), expon);
	}

	@Override
	public FunctionIF diff()
	{
		if (expon == 0)
			return new PolynTerm(1, 0);

		Function p = (Function) function.clone();
		p.expon = -1;
		p.coff = 1;

		FunctionIF d_poly = function.diff();
		return returnDerivative(p, d_poly);
	}

	@Override
	protected Object clone()
	{
		return new Ln(coff, expon, (Function) function.clone());
	}

	@Override
	public String toString()
	{
		if (expon == 1)
			return coff + "*ln(" + function.toString() + ")";
		else
			return coff + "*ln(" + function.toString() + ")^" + expon;

	}
}
